class artModel{
  constructor(){
    this.db = require('../../config/db')
  }
  //获取艺术涂料所有信息
  art(){
    let sql = 'select * from art order by pubdate DESC'
    return this.db.query(sql)
  }
  details(){
    let sql = 'select * from details1'
    return this.db.query(sql)
  }
  // item(){
  //   let sql = 'select * from item1'
  //   return this.db.query(sql)
  // }
  //查询艺术涂料所有信息
  queryArt(query,pagenum,pagesize){
    let sql = 'select * from art'
    if(query != null || query != ""){
      sql += " where classify like '%"+ query +"%'"
    }
    sql += " order by pubdate DESC limit ?,?"
    console.log(sql)
    return this.db.query(sql,[pagenum,pagesize])
  }
  //查询艺术涂料所有
  queryArtTotal(query){
    let sql = 'select * from art'
    if(query != null || query != ""){
      sql += " where classify like '%"+ query +"%'"
    }
    return this.db.query(sql)
  }
  //id查询艺术涂料所有信息
  artID(id){
    let sql = 'select * from art where id = ?'
    return this.db.query(sql,[id])
  }
  detailsID(father){
    let sql = 'select * from details1 where father = ?'
    return this.db.query(sql,[father])
  }
  // itemID(father){
  //   let sql = 'select * from item1 where father = ?'
  //   return this.db.query(sql,[father])
  // }
  //添加艺术涂料所有信息
  addArt(title,img,EnglishName,classify){
    let sql = 'insert into art (title,img,EnglishName,classify,shows,is_active) values (?,?,?,?,0,0)'
    return this.db.query(sql,[title,img,EnglishName,classify])
  }
  //添加艺术涂料所有信息
  addDetails(father,title,img,article){
    console.log()
    let sql = 'insert into details1 (father,title,img,article) values (?,?,?,?)'
    return this.db.query(sql,[father,title,img,article])
  }
  //添加艺术涂料列表
  // addList(father,title,content,img){
  //   let sql = 'insert into item1 (father,title,img,content) values (?,?,?,?)'
  //   return this.db.query(sql,[father,title,img,content])
  // }

  //修改艺术涂料列表
  updateArt(title,img,EnglishName,classify,id){
    let sql = 'update art set title = ?,img = ?,EnglishName = ?,classify = ? where id =?'
    return this.db.query(sql,[title,img,EnglishName,classify,id])
  }
  updateDetails(title,img,article,father){
    let sql = 'update details1 set title = ?,img = ?,article = ? where father = ?'
    return this.db.query(sql,[title,img,article,father])
  }
  // updateList(title,content,img,father){
  //   let sql = 'update item1 set title = ?,content = ?,img = ? where father = ?'
  //   return this.db.query(sql,[title,content,img,father])
  // }

  //删除艺术涂料所有信息
  deleteArt(id){
    let sql = 'delete from art where id = ?'
    return this.db.query(sql,[id])
  }
  deleteDetails(father){
    let sql = 'delete from details1 where father = ?'
    return this.db.query(sql,[father])
  }
  // deleteList(father){
  //   let sql = 'delete from item1 where father = ?'
  //   return this.db.query(sql,[father])
  // }
}

module.exports = new artModel()